Repository navigation
Stabilize master CI: deterministic timing, cancel precedence, and Windows bounds - #328
Conversation
…clock (RM38; AC29)
PR Reviewer Guide 🔍(Review updated until commit b26e45a)Here are some key observations to aid the review process:
✅ Resolved findingstests/test_openclaw_install_check.py:765-770Question: killpg/SIGKILL on Windows The new |
DeepSeek review: Not approved (
|
devnullexile
left a comment
There was a problem hiding this comment.
The revised timing test misses a response-latency regression, and the Windows lifecycle deadline can discard the timeout evidence it is meant to capture.
| # The Windows runner spends 200-220 s in the host's npm install alone | ||
| # (about 30 s on Linux and macOS), so its per-command bound is wider. | ||
| # A real hang still fails here instead of at the 60-minute job limit. | ||
| timeout-minutes: 20 |
There was a problem hiding this comment.
[P2] should fix. If plugins inspect times out after installation and plugins uninstall also stalls during cleanup, their two 600-second waits plus installation exceed this 20-minute cap. The runner stops the script before it writes the lifecycle JSON, losing the timed_out record. Reserve time for the export within the step deadline or write the failure record before cleanup.
There was a problem hiding this comment.
Confirmed. The 20-minute step cap is 1200 s, while a 200-220 s Windows install plus the 600 s inspect timeout plus a 600 s uninstall stall is already about 1400 s, and run_steps keeps running the cleanup steps after a timeout. run_install_check writes the JSON only after run_steps returns (scripts/openclaw_install_check.py), so the runner kills the process before the timed_out record exists. I will reserve time for the export in the step deadline, or write the failure record before cleanup.
There was a problem hiding this comment.
Fixed in 0f6aec6. The step passes --budget 1140 under the 1200 s cap; run_install_check reserves EXPORT_RESERVE_SECONDS = 30 and gives each command min(timeout, remaining), so a 600 s inspect plus a stalled uninstall cannot consume the export window. test_openclaw_lifecycle_has_a_wider_windows_command_timeout and test_a_lifecycle_budget_stops_a_stalled_cleanup_before_the_export cover it.
| await asyncio.sleep(0.05) | ||
| return httpx.Response(200, json={}) | ||
|
|
||
| clock = FakeClock() |
There was a problem hiding this comment.
[P2] should fix. This clock never advances, so client_elapsed_ms stays at zero even if request_sample records the evidence timeout as the response completion time. I verified that the test still passes with that regression. Advance the clock when the POST completes and again when evidence collection times out, then assert the POST duration.
There was a problem hiding this comment.
Fixed in 0f6aec6. FakeClock advances 10 ms on the POST and 5 s on the evidence timeout, and the assertion is client_elapsed_ms == 10; recording the timeout as the response completion would fail the test.
Add a lifecycle budget to the OpenClaw install check and pass 1140 s from the CI step, so a stalled cleanup cannot let the 20-minute step deadline kill the process before the JSON export is written. Record the budget and the effective per-step timeout in the export. Make the asset timing test advance FakeClock at the POST completion and at the evidence timeout, then assert the POST duration, so it fails when a timeout is recorded as the response completion. RM33; RM38; AC24; AC29.
devnullexile
left a comment
There was a problem hiding this comment.
The earlier response-latency comment is resolved. The test now distinguishes POST completion from the evidence timeout. The earlier comment about stacking full command timeouts is also resolved by capping each command to the remaining lifecycle budget. The inline comments cover separate issues with Windows process shutdown, cleanup test coverage, and budget input.
| try: | ||
| code, stdout, stderr, timed_out, seconds = _run(command, args, stdin, ctx.env, timeout) | ||
| code, stdout, stderr, timed_out, seconds = _run( | ||
| command, args, stdin, ctx.env, step_timeout |
There was a problem hiding this comment.
[P2] Enforce the lifecycle deadline across Windows child processes
The pinned OpenClaw CLI respawns plugins uninstall on Windows with inherited stdout and stderr, even when launched directly through node. When the timeout expires, CPython kills the immediate process and drains the pipes without a timeout. A stalled OpenClaw child can hold those pipes open until Actions kills the step, so this command can exceed its remaining budget and prevent the JSON export. Terminate the process tree on timeout and bound the final output read. The install helper’s _stop already handles both.
OpenClaw respawn · Inherited stdio · CPython timeout behavior
There was a problem hiding this comment.
Fixed in fac711a. _run now starts the host in its own process group, stops the tree on timeout (taskkill /T /F on Windows, killpg on POSIX), and writes stdout/stderr to temporary files, so a respawned child cannot hold inherited pipes past the budget. A unit test covers both timeout paths.
| monkeypatch.setenv("STUB_STALL", "plugins inspect,plugins uninstall") | ||
| monkeypatch.setenv("STUB_STALL_SECONDS", "10") | ||
| monkeypatch.setattr(install_check, "EXPORT_RESERVE_SECONDS", 0.1) | ||
| export = run(stub_host, tarball, tmp_path, timeout=10, budget=3) |
There was a problem hiding this comment.
[P2] Exercise the cleanup deadline with an injected clock
The stalled inspect consumes the budget before uninstall starts. I verified that the test still passes when cleanup ignores the deadline and uninstall waits the full 10 seconds. The test also fails if runner delays consume the 2.9-second command window before inspect starts. Have inspect fail promptly, simulate an uninstall stall using an injected clock, and assert that uninstall gets only the remaining budget and the export is written.
| parser.add_argument("--timeout", type=float, default=300, help="seconds per host command") | ||
| parser.add_argument( | ||
| "--budget", | ||
| type=float, |
There was a problem hiding this comment.
[P3] Reject non-finite lifecycle budgets
--budget nan is accepted, leaves the full per-command timeout in effect, and writes "budget_seconds": NaN, which strict JSON readers reject. I reproduced this with a successful stub-host run. Reject non-finite values at argument parsing before starting the lifecycle.
There was a problem hiding this comment.
Fixed in fac711a. --budget and --timeout now use a finite-float parser and reject nan/inf/-inf before the lifecycle starts; run_install_check also rejects non-finite values. A test covers the parser and the direct call.
…33; AC24) Run host commands in their own process group, stop the whole tree on timeout, and read stdout/stderr from temporary files so a Windows respawn cannot hold inherited pipes past the budget. Make the cleanup-deadline test inject the lifecycle clock, time out inspect promptly, stall uninstall, and assert the remaining budget and the export. Reject non-finite timeout and budget values before the lifecycle starts.
| else: | ||
|
|
||
| def fake_killpg(pid, sig): | ||
| calls.append(("killpg", pid, sig)) | ||
|
|
||
| monkeypatch.setattr(install_check.os, "killpg", fake_killpg) |
There was a problem hiding this comment.
Question: killpg/SIGKILL on Windows
The new test_a_timed_out_host_command_stops_the_process_tree case for
platform == "linux" monkeypatches os.killpg and relies on
signal.SIGKILL. Both are Unix-only stdlib members. On a windows-latest
runner (the full suite runs this file there), monkeypatch.setattr(install_check.os, "killpg", ...) raises AttributeError because os.killpg is absent on
Windows, so the test errors in the Windows job; even if that patch used
raising=False, _stop_tree would then fail evaluating signal.SIGKILL.
That would make Windows CI red on the very test added to stabilize it.
Suggested correction: skip the linux parametrization on Windows, or patch
both os.killpg and signal.SIGKILL with raising=False (or route the
signal through a small module-level indirection) so the simulated branch can
run cross-platform. Worth confirming on a real Windows runner.
There was a problem hiding this comment.
Fixed at 188af77. The linux parametrization is skipped on win32 (tests/test_openclaw_install_check.py:771), and the PermissionError test is also skipped there (:837), so os.killpg and signal.SIGKILL are not evaluated on Windows.
devnullexile
left a comment
There was a problem hiding this comment.
All three comments from the earlier review are resolved: _run now stops the process tree on timeout and reads stdout/stderr from temporary files instead of pipes, the cleanup-deadline test uses an injected clock and verifies the remaining budget and export, and non-finite --budget/--timeout values are rejected before the lifecycle starts. One inline note on a macOS os.killpg race in _stop_tree.
| else: | ||
| try: | ||
| os.killpg(process.pid, signal.SIGKILL) | ||
| except ProcessLookupError: |
There was a problem hiding this comment.
[P3] Catch PermissionError from os.killpg on macOS
On macOS, os.killpg(process.pid, signal.SIGKILL) raises PermissionError (EPERM) if the host exits between process.wait() timing out and killpg running (while the process group leader is an unreaped zombie). Unlike os.kill, that error escapes _stop_tree without reaping the child and falls into run_steps's except OSError handler, which misrecords the timed-out step as not_run and drops its captured output.
| except ProcessLookupError: | |
| except (ProcessLookupError, PermissionError): |
There was a problem hiding this comment.
Fixed in 188af77. _stop_tree catches (ProcessLookupError, PermissionError) around os.killpg, so a macOS EPERM no longer escapes to run_steps; test_a_permission_error_from_killpg_keeps_the_timeout_evidence checks the timed_out status and the captured output.
ArcsinX
left a comment
There was a problem hiding this comment.
Found a few issues to address before merging:
- Windows CI is currently red:
test_a_timed_out_host_command_stops_the_process_tree[linux]intests/test_openclaw_install_check.pyfails onwindows-latestin bothcheckandopenclaw-pluginwithAttributeError: <module 'os' (frozen)> has no attribute 'killpg'(andsignal.SIGKILLis also absent on Windows). - Cancel precedence gaps in orchestrator:
_publishinsrc/relaymind/orchestrator/publish.pydoes not checkself.cancel_requested(unlike_publication_ready), so buffered/draft answers can persistanswer.deltabefore_run_local/_run_externalcancels the run. In addition,_clarify,_escalate(local_loop.py), and_escalate_client(client_loop.py) do not checkself.cancel_requestedbefore transitioning toWAITING_INPUT/EXTERNAL_RUNNINGor calling externalhealth()/measure_request(). - Non-positive lifecycle
timeout/budget:scripts/openclaw_install_check.pyrejectsnan/infbut still accepts<= 0(orbudget <= EXPORT_RESERVE_SECONDS), which silently skips all steps or immediately times out.
(Note: platform-run (ubuntu-latest) failed on an Ubuntu apt mirror network error during Playwright browser install, unrelated to this PR.)
The linux parameter patches os.killpg and asserts signal.SIGKILL, both POSIX-only, so it cannot run on Windows. The win32 parameter still covers the Windows branch, and the POSIX branch remains covered on Linux and macOS.
…or (RM33; AC24) Treat a PermissionError from os.killpg like a missing process. The timeout path still reaps the child, reads the captured stdout/stderr, and reports timed_out instead of falling through to run_steps' OSError path, which recorded the step as not_run.
ArcsinX
left a comment
There was a problem hiding this comment.
Re-reviewed at 188af77966aa0591e3393dd3c1394a102251dc9a:
- Resolved:
test_a_timed_out_host_command_stops_the_process_tree[linux]is now skipped onwin32(andtest_a_permission_error_from_killpg_keeps_the_timeout_evidenceis also skipped onwin32). - Still open from previous review:
_publishinsrc/relaymind/orchestrator/publish.pystill lacks aself.cancel_requestedguard._escalate_client(client_loop.py) and_escalate/_clarify(local_loop.py) still lackself.cancel_requestedchecks.scripts/openclaw_install_check.pystill acceptstimeout <= 0andbudget <= EXPORT_RESERVE_SECONDS(or<= 0).
- New findings (inline): additional cancel-precedence gaps in
src/relaymind/orchestrator/generation.py(except BudgetExceededError/ post-finallyerror paths) and_await_confirmation(src/relaymind/orchestrator/confirmation.py, called atlocal_loop.py:1608).
ArcsinX
left a comment
There was a problem hiding this comment.
Re-reviewed at e67749747cdbea12173c5ebf4d7b19ab617c5cd6 and resolved the previously addressed ArcsinX threads. Found two remaining cancel_requested windows across awaits in _escalate_client, _hand_off, and _run_parallel.
…llel join (RM14; AC12)
ArcsinX
left a comment
There was a problem hiding this comment.
LGTM. Re-reviewed at 95743426b085c9fd90786887f69418fada10cd12: both remaining cancel_requested windows across awaits in _escalate_client, _hand_off, and _run_parallel are fixed with targeted regression tests, and both ArcsinX threads have been resolved. Note: CI checks on 95743426b085c9fd90786887f69418fada10cd12 were still pending at review time.
devnullexile
left a comment
There was a problem hiding this comment.
My earlier macOS killpg comment is resolved. The PermissionError path now preserves the timed_out status and captured output. The earlier POST timing, lifecycle deadline, Windows process-tree shutdown, cleanup deadline coverage, and non-finite input comments are also resolved.
| monkeypatch.setattr(run, "_checklist_branch", branch) | ||
| outcome = asyncio.run(run._run_parallel(None)) | ||
| assert outcome.state is RunState.CANCELLED | ||
| assert gateway.store.get_run(run.run_id).state == "cancelled" |
There was a problem hiding this comment.
[P2] Assert that cancellation prevents the parallel workflow from starting
I verified that this test still passes with the post-measurement cancel check removed. The run enters PARALLEL_RUNNING and both branch doubles run, then the post-join check returns CANCELLED and both assertions pass. Check that the workflow never started so the test catches a regression in the RM14/AC12 dispatch guarantee.
| assert gateway.store.get_run(run.run_id).state == "cancelled" | |
| assert gateway.store.get_run(run.run_id).state == "cancelled" | |
| assert run.workflow is None |
There was a problem hiding this comment.
Fixed in b26e45a. test_parallel_cancel_during_measure_returns_cancelled now asserts run.workflow is None, so it fails if the run enters PARALLEL_RUNNING and starts the branches; the post-join cancel remains covered by test_parallel_cancel_after_branches_returns_cancelled.
… cancel (RM14; AC12)
Summary
Master CI failures over the last five weeks were not random. Most were Windows timing flakes and bounds that were too tight; two were macOS arm64 runner acquisition failures on GitHub's side. This PR removes the controllable flakes and documents the remaining rerun path.
What changed
failedor publish that text. Added a deterministic regression test that consumesCancelledError, advances the clock, and yields late text.test_event_fetch_timeout...now uses the injectedFakeClock; the assertion no longer depends on Windows timer granularity.--timeout 600onwindows-latest(300 elsewhere), writestimeout_secondsto the export, and has a 20-minute step bound. Windows install has been 203.8 / 217.4 / 222.0 s in passing runs, against ~28-33 s on Linux/macOS; the old 300 s default was too tight.The job was not acquired by Runner of type hostedis GitHub capacity and should be rerun; failed tests must not be retried.What is not fixed
macOS arm64 runner acquisition is GitHub capacity, not repository behavior. The two 30 Nov cancellations happened after ~15 minutes without a runner (
The job was not acquired...). This PR keeps the arm64 matrix and documents the honest fallback: rerun those jobs. It does not auto-rerun or hide test failures.Verification
pytest -n auto --dist loadfile: 10866 passed, 38 skippednpm --prefix integrations/openclaw test: 1013 passed, 1 skippednpm --prefix integrations/openclaw run typecheckruff check .ruff format --check .pytest tests/test_ci_workflows.py tests/test_documentation_links.pyfailed/external_failed) and passes after.Requirements
RM14, RM33, RM38; AC12, AC19, AC24, AC29. No specification revision: the cancel precedence implements the existing section 7.4 rule; the rest is test/CI only.